package com.ruoyi.stock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockBasic;
import com.ruoyi.stock.service.IStockBasicService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 股票基本信息Controller
 *
 * @author ruoyi
 * @date 2021-10-22
 */
@RestController
@RequestMapping("/stock/basic")
public class StockBasicController extends BaseController {
  @Autowired private IStockBasicService stockBasicService;

  /** 查询股票基本信息列表 */
  @PreAuthorize("@ss.hasPermi('stock:basic:list')")
  @GetMapping("/list")
  public TableDataInfo list(StockBasic stockBasic) {
    startPage();
    List<StockBasic> list = stockBasicService.selectStockBasicList(stockBasic);
    return getDataTable(list);
  }

  /** 导出股票基本信息列表 */
  @PreAuthorize("@ss.hasPermi('stock:basic:export')")
  @Log(title = "股票基本信息", businessType = BusinessType.EXPORT)
  @GetMapping("/export")
  public AjaxResult export(StockBasic stockBasic) {
    List<StockBasic> list = stockBasicService.selectStockBasicList(stockBasic);
    ExcelUtil<StockBasic> util = new ExcelUtil<StockBasic>(StockBasic.class);
    return util.exportExcel(list, "股票基本信息数据");
  }

  /** 获取股票基本信息详细信息 */
  @PreAuthorize("@ss.hasPermi('stock:basic:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return AjaxResult.success(stockBasicService.selectStockBasicById(id));
  }

  /** 新增股票基本信息 */
  @PreAuthorize("@ss.hasPermi('stock:basic:add')")
  @Log(title = "股票基本信息", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(@RequestBody StockBasic stockBasic) {
    return toAjax(stockBasicService.insertStockBasic(stockBasic));
  }

  /** 修改股票基本信息 */
  @PreAuthorize("@ss.hasPermi('stock:basic:edit')")
  @Log(title = "股票基本信息", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(@RequestBody StockBasic stockBasic) {
    return toAjax(stockBasicService.updateStockBasic(stockBasic));
  }

  /** 删除股票基本信息 */
  @PreAuthorize("@ss.hasPermi('stock:basic:remove')")
  @Log(title = "股票基本信息", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(stockBasicService.deleteStockBasicByIds(ids));
  }
}
